import 'package:cbec_app/components/base/base_icon.dart';
import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///服务条款弹框
class ServiceDetailPopup extends StatefulWidget {
  ///条款列表
  final List? serviceList;
  const ServiceDetailPopup({super.key, this.serviceList});

  @override
  State<StatefulWidget> createState() {
    return _ServiceDetailPopupState();
  }
}

class _ServiceDetailPopupState extends State<ServiceDetailPopup> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 445.h,
      decoration: const BoxDecoration(
          color: Color(0xffFFD569),
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(16), topRight: Radius.circular(16))),
      child: Stack(
        fit: StackFit.expand,
        children: [
          Positioned(
              top: 18,
              right: 18,
              child: BaseInteractive(
                childWidget: Icon(Icons.close),
                onClick: () {
                  Get.back();
                },
              )),
          Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              Padding(
                padding: EdgeInsets.only(top: 10.h),
                child: Text(
                  '服务安心保障',
                  style: setTextStyle(15, FontWeight.w700, Color(0xffAD4D06)),
                ),
              ),
              Padding(
                padding: EdgeInsets.only(top: 5.h),
                child: Text(
                  '售前售后安心无忧购物',
                  style: setTextStyle(12, FontWeight.w400, Color(0xffAD4D06)),
                ),
              ),
              Container(
                width: 360.w,
                height: 280.h,
                margin: EdgeInsets.only(top: 10.h, left: 8.w, right: 8.w),
                decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(16),
                        topRight: Radius.circular(16))),
                child: Container(
                  margin: EdgeInsets.only(
                      top: 20.h, left: 15.w, right: 5.w, bottom: 20.h),
                  child: Column(
                      children: widget.serviceList!
                          .map((item) => Container(
                                margin: EdgeInsets.only(bottom: 20.h),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    BaseImage(
                                      url: 'service_icon.png',
                                      width: 24,
                                    ),
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                       Container(
                                        margin: EdgeInsets.only(left: 4.w),
                                        width: 300.w,
                                        child: Text(
                                            item['serviceName'] ?? '',
                                            style: setTextStyle(
                                                14,
                                                FontWeight.w500,
                                                ThemeConfig.mainTextColor),
                                          ),
                                       ),
                                        Container(
                                            margin: EdgeInsets.only(top: 12),
                                            width:300.w ,
                                            child: Text(
                                              item['serviceDescription'] ?? '',
                                              style: setTextStyle(
                                                  12,
                                                  FontWeight.w300,
                                                  ThemeConfig.sectionTextColor),
                                            )),
                                      ],
                                    )
                                  ],
                                ),
                              ))
                          .toList()),
                ),
              )
            ],
          ),
          Positioned(
              left: 0,
              bottom: MediaQuery.of(context).padding.bottom,
              child: Container(
                width: 375.w,
                padding: EdgeInsets.only(top: 10.h, bottom: 10.h),
                color: Colors.white,
                child: solidButton('确定',
                    backgroundColor: Color(0xffFFD569),
                    textColor: Color(0xffAD4D06), () {
                  Get.back();
                }),
              ))
        ],
      ),
    );
  }
}

///显示服务条款
void showServiceDetailPopup(List? serviceList) {
  Get.bottomSheet(StatefulBuilder(
    builder: (context, setState) {
      return ServiceDetailPopup(
        serviceList: serviceList,
      );
    },
  ));
}
